#!/bin/sh
#
#
#
PATH=$PWD:$PATH
export GIT_PAGER=cat

set -e

rm -rf checkdir
mkdir -p checkdir/master checkdir/master2 checkdir/masterprep checkdir/masterprep2
BASE=`pwd`
(cd checkdir/masterprep
 for f in top sub1 sub2 sub3
  do
   mkdir $f
   (cd $f
    git init
    date > datelist
    echo $f > packagename
    git add *
    git commit -a -m "Initial files"
    cd ../../master; git clone --bare --mirror ../masterprep/$f $f)
  done)
(cd checkdir/masterprep2
 for f in top2 sub21
  do
   mkdir $f
   (cd $f
    git init
    date > datelist
    echo $f > packagename
    git add *
    git commit -a -m "Initial files"
    cd ../../master2; git clone --bare --mirror ../masterprep2/$f $f)
  done)

git clone $BASE/checkdir/master/top $BASE/checkdir/slave
cd checkdir/slave
echo
echo Starting gits checks
echo ----------------------------------------------------------------------
set -x
: Configure the git slave setup and upload it
GITS_DIR=`pwd` gits prepare
gits attach ../sub1 sub1
gits attach --adminonly ../sub2 sub2
gits populate
gits push
: Someone else gets a copy of the package and git slave config
gits clone $BASE/checkdir/master/top $BASE/checkdir/slave2
cd ../slave2
:  Actually instantiate the slaves
#gits populate
gits pull
:  Make some mods and commit
date >> datelist
date >> sub1/datelist
gits status
gits commit -a -m "First stage updates"
gits push
: Get the latest changes, create another slave and publish it
cd ../slave
gits pull
git clone $BASE/checkdir/master/sub3
gits attach --adminonly ../sub3 sub3
gits push
: Person2 gets the new slave module
cd ../slave2
gits pull
gits populate
: Create a private branch and do work on it
cd ../slave
gits pull
gits checkout -b privateb master
date >> sub2/datelist
gits commit -a -m "Updating date in sub2 on branch privateb"
# Now fails with error "not tracking anything" which is very true
#gits push
: "Person2 checks, but no changes (and no new branch), makes a change, commits"
cd ../slave2
gits pull
gits populate
gits branch -a
date >> datelist
gits commit -a -m "Updating date in top"
gits push
: Person1 makes another change, checks to see latest changes, merges branch, then publishes
cd ../slave
gits fetch
gits diff master origin/master
date >> sub2/datelist
gits commit -a -m "Finish updating date in sub2 on branch privateb"
gits checkout master
gits pull
# "Also works, but Seth does not like fastforward's rewriting of history"
#gits merge privateb
gits merge --no-ff privateb
gits push
: Person2 finds changes, makes another, commit/publish
cd ../slave2
gits pull
date >> sub2/datelist
gits commit -a -m "Back at you!"
gits push
cd ../slave
: "Delete private branch to prevent accidential publish (e.g. push -all)"
gits branch -d privateb
: "Get latest changes, make public branch"
gits pull
gits tag -m "Release 1.0.0" 'checkdir-1.0.0'
gits push --tags
gits branch 'checkdir-1.0'
gits push --all
: "stupid: my local branch and remote origin branch are disconnected, reconnect them"
gits branch -d checkdir-1.0
gits branch checkdir-1.0 origin/checkdir-1.0
gits push --all
: "Person2 discovers new release/tag/branch, pulls himself onto branch"
cd ../slave2
gits pull
gits branch -a
gits tag -l
gits branch checkdir-1.0 origin/checkdir-1.0
gits checkout checkdir-1.0
: "Fixes bug, merges fix onto master, publishes changes"
date >> sub2/datelist
gits commit -a -m "Sigh, a bug in the new release"
gits checkout master
gits merge --no-ff checkdir-1.0
gits push --all
: "Person1 takes change, finds another bug, repeat"
cd ../slave
gits pull
gits checkout master
(date; cat sub2/datelist) > sub2/datelist1
mv sub2/datelist1  sub2/datelist
gits commit -a -m "I am reminded that this is needed for 2.x"
gits checkout checkdir-1.0
gits pull
date >> sub2/datelist
gits commit -a -m "Sigh, and another bug in the new release"
gits checkout master
gits pull
gits merge --no-ff checkdir-1.0
gits push
: "Person 3 tried to look at checkdir-1.0 directly"
cd ..
git clone $BASE/checkdir/master/top $BASE/checkdir/slave3
cd slave3
git branch checkdir-1.0 origin/checkdir-1.0
git checkout checkdir-1.0
gits populate
if gits status | grep ' != slave branch'; then exit 1; fi
: "Person 3 wants to nuke remove sub2"
gits detach sub2
: "Person 3 wants to nuke remove sub3 the hard way"
gits release sub3
gits detach sub3
: "Test a few relative URL schemes"
gits remote add ssher ssh://example.com/repo/dir
gits remote add ssheru ssh://user@example.com/repo/dir
gits remote add sshgit git+ssh://example.com/CommonRepo
gits remote add scper example.com:/repo/dir
gits remote add scperu user@example.com:/repo/dir
gits remote add scperd example.com:repo
gits remote add --fromcheckout fssher ssh://example.com/repo/dir
gits remote add --fromcheckout fssheru ssh://user@example.com/repo/dir
gits remote add --fromcheckout fsshgit git+ssh://example.com/CommonRepo
gits remote add --fromcheckout fscper example.com:/repo/dir
gits remote add --fromcheckout fscperu user@example.com:/repo/dir
gits remote add --fromcheckout fscperd example.com:repo
: perl -e '@tests=("test1 TEST1", "--fromcheckout test1 TEST1", "--no-fromcheckout test1 TEST1", "../test1 TEST1",
              ".././//test1 TEST1", "/path/to/test1 TEST1", ".. TEST1", "^/path/to/test1 TEST1",
              "ssh://example.org/test1 TEST1", "example.org:test1 TEST1");
      @repos=("", "ssher", "fssher", "ssheru", "fssheru", "sshgit", "fsshgit", "scper", "fscper", "scperu", "fscperu", "scperd", "fscperd");
      foreach my $repo (@repos) { foreach my $test (@tests) {
        $cmd = "gits resolve $test $repo";
        $out = `$cmd`;
        chomp($out);
        $bquote = quotemeta($ENV{"BASE"});
        $out =~ s/$bquote/\$BASE/;
        print qq^if [ \`$cmd\` != "$out" ]; then exit 1; fi\n^;
     } print "\n"; }'

if [ `gits resolve test1 TEST1 ` != "$BASE/checkdir/master/top/test1" ]; then exit 1; fi
if [ `gits resolve --fromcheckout test1 TEST1 ` != "$BASE/checkdir/master/top/TEST1" ]; then exit 1; fi
if [ `gits resolve --no-fromcheckout test1 TEST1 ` != "$BASE/checkdir/master/top/test1" ]; then exit 1; fi
if [ `gits resolve ../test1 TEST1 ` != "$BASE/checkdir/master/test1" ]; then exit 1; fi
if [ `gits resolve .././//test1 TEST1 ` != "$BASE/checkdir/master/test1" ]; then exit 1; fi
if [ `gits resolve /path/to/test1 TEST1 ` != "/path/to/test1" ]; then exit 1; fi
if [ `gits resolve .. TEST1 ` != "$BASE/checkdir/master/" ]; then exit 1; fi
if [ `gits resolve ^/path/to/test1 TEST1 ` != "/path/to/test1" ]; then exit 1; fi
if [ `gits resolve ssh://example.org/test1 TEST1 ` != "ssh://example.org/test1" ]; then exit 1; fi
if [ `gits resolve example.org:test1 TEST1 ` != "example.org:test1" ]; then exit 1; fi

if [ `gits resolve test1 TEST1 ssher` != "ssh://example.com/repo/dir/test1" ]; then exit 1; fi
if [ `gits resolve --fromcheckout test1 TEST1 ssher` != "ssh://example.com/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve --no-fromcheckout test1 TEST1 ssher` != "ssh://example.com/repo/dir/test1" ]; then exit 1; fi
if [ `gits resolve ../test1 TEST1 ssher` != "ssh://example.com/repo/test1" ]; then exit 1; fi
if [ `gits resolve .././//test1 TEST1 ssher` != "ssh://example.com/repo/test1" ]; then exit 1; fi
if [ `gits resolve /path/to/test1 TEST1 ssher` != "/path/to/test1" ]; then exit 1; fi
if [ `gits resolve .. TEST1 ssher` != "ssh://example.com/repo/" ]; then exit 1; fi
if [ `gits resolve ^/path/to/test1 TEST1 ssher` != "ssh://example.com/path/to/test1" ]; then exit 1; fi
if [ `gits resolve ssh://example.org/test1 TEST1 ssher` != "ssh://example.org/test1" ]; then exit 1; fi
if [ `gits resolve example.org:test1 TEST1 ssher` != "example.org:test1" ]; then exit 1; fi

if [ `gits resolve test1 TEST1 fssher` != "ssh://example.com/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve --fromcheckout test1 TEST1 fssher` != "ssh://example.com/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve --no-fromcheckout test1 TEST1 fssher` != "ssh://example.com/repo/dir/test1" ]; then exit 1; fi
if [ `gits resolve ../test1 TEST1 fssher` != "ssh://example.com/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve .././//test1 TEST1 fssher` != "ssh://example.com/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve /path/to/test1 TEST1 fssher` != "ssh://example.com/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve .. TEST1 fssher` != "ssh://example.com/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve ^/path/to/test1 TEST1 fssher` != "ssh://example.com/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve ssh://example.org/test1 TEST1 fssher` != "ssh://example.com/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve example.org:test1 TEST1 fssher` != "ssh://example.com/repo/dir/TEST1" ]; then exit 1; fi

if [ `gits resolve test1 TEST1 ssheru` != "ssh://user@example.com/repo/dir/test1" ]; then exit 1; fi
if [ `gits resolve --fromcheckout test1 TEST1 ssheru` != "ssh://user@example.com/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve --no-fromcheckout test1 TEST1 ssheru` != "ssh://user@example.com/repo/dir/test1" ]; then exit 1; fi
if [ `gits resolve ../test1 TEST1 ssheru` != "ssh://user@example.com/repo/test1" ]; then exit 1; fi
if [ `gits resolve .././//test1 TEST1 ssheru` != "ssh://user@example.com/repo/test1" ]; then exit 1; fi
if [ `gits resolve /path/to/test1 TEST1 ssheru` != "/path/to/test1" ]; then exit 1; fi
if [ `gits resolve .. TEST1 ssheru` != "ssh://user@example.com/repo/" ]; then exit 1; fi
if [ `gits resolve ^/path/to/test1 TEST1 ssheru` != "ssh://user@example.com/path/to/test1" ]; then exit 1; fi
if [ `gits resolve ssh://example.org/test1 TEST1 ssheru` != "ssh://example.org/test1" ]; then exit 1; fi
if [ `gits resolve example.org:test1 TEST1 ssheru` != "example.org:test1" ]; then exit 1; fi

if [ `gits resolve test1 TEST1 fssheru` != "ssh://user@example.com/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve --fromcheckout test1 TEST1 fssheru` != "ssh://user@example.com/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve --no-fromcheckout test1 TEST1 fssheru` != "ssh://user@example.com/repo/dir/test1" ]; then exit 1; fi
if [ `gits resolve ../test1 TEST1 fssheru` != "ssh://user@example.com/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve .././//test1 TEST1 fssheru` != "ssh://user@example.com/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve /path/to/test1 TEST1 fssheru` != "ssh://user@example.com/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve .. TEST1 fssheru` != "ssh://user@example.com/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve ^/path/to/test1 TEST1 fssheru` != "ssh://user@example.com/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve ssh://example.org/test1 TEST1 fssheru` != "ssh://user@example.com/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve example.org:test1 TEST1 fssheru` != "ssh://user@example.com/repo/dir/TEST1" ]; then exit 1; fi

if [ `gits resolve test1 TEST1 sshgit` != "git+ssh://example.com/CommonRepo/test1" ]; then exit 1; fi
if [ `gits resolve --fromcheckout test1 TEST1 sshgit` != "git+ssh://example.com/CommonRepo/TEST1" ]; then exit 1; fi
if [ `gits resolve --no-fromcheckout test1 TEST1 sshgit` != "git+ssh://example.com/CommonRepo/test1" ]; then exit 1; fi
if [ `gits resolve ../test1 TEST1 sshgit` != "git+ssh://example.com/test1" ]; then exit 1; fi
if [ `gits resolve .././//test1 TEST1 sshgit` != "git+ssh://example.com/test1" ]; then exit 1; fi
if [ `gits resolve /path/to/test1 TEST1 sshgit` != "/path/to/test1" ]; then exit 1; fi
if [ `gits resolve .. TEST1 sshgit` != "git+ssh://example.com/" ]; then exit 1; fi
if [ `gits resolve ^/path/to/test1 TEST1 sshgit` != "git+ssh://example.com/path/to/test1" ]; then exit 1; fi
if [ `gits resolve ssh://example.org/test1 TEST1 sshgit` != "ssh://example.org/test1" ]; then exit 1; fi
if [ `gits resolve example.org:test1 TEST1 sshgit` != "example.org:test1" ]; then exit 1; fi

if [ `gits resolve test1 TEST1 fsshgit` != "git+ssh://example.com/CommonRepo/TEST1" ]; then exit 1; fi
if [ `gits resolve --fromcheckout test1 TEST1 fsshgit` != "git+ssh://example.com/CommonRepo/TEST1" ]; then exit 1; fi
if [ `gits resolve --no-fromcheckout test1 TEST1 fsshgit` != "git+ssh://example.com/CommonRepo/test1" ]; then exit 1; fi
if [ `gits resolve ../test1 TEST1 fsshgit` != "git+ssh://example.com/CommonRepo/TEST1" ]; then exit 1; fi
if [ `gits resolve .././//test1 TEST1 fsshgit` != "git+ssh://example.com/CommonRepo/TEST1" ]; then exit 1; fi
if [ `gits resolve /path/to/test1 TEST1 fsshgit` != "git+ssh://example.com/CommonRepo/TEST1" ]; then exit 1; fi
if [ `gits resolve .. TEST1 fsshgit` != "git+ssh://example.com/CommonRepo/TEST1" ]; then exit 1; fi
if [ `gits resolve ^/path/to/test1 TEST1 fsshgit` != "git+ssh://example.com/CommonRepo/TEST1" ]; then exit 1; fi
if [ `gits resolve ssh://example.org/test1 TEST1 fsshgit` != "git+ssh://example.com/CommonRepo/TEST1" ]; then exit 1; fi
if [ `gits resolve example.org:test1 TEST1 fsshgit` != "git+ssh://example.com/CommonRepo/TEST1" ]; then exit 1; fi

if [ `gits resolve test1 TEST1 scper` != "example.com:/repo/dir/test1" ]; then exit 1; fi
if [ `gits resolve --fromcheckout test1 TEST1 scper` != "example.com:/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve --no-fromcheckout test1 TEST1 scper` != "example.com:/repo/dir/test1" ]; then exit 1; fi
if [ `gits resolve ../test1 TEST1 scper` != "example.com:/repo/test1" ]; then exit 1; fi
if [ `gits resolve .././//test1 TEST1 scper` != "example.com:/repo/test1" ]; then exit 1; fi
if [ `gits resolve /path/to/test1 TEST1 scper` != "/path/to/test1" ]; then exit 1; fi
if [ `gits resolve .. TEST1 scper` != "example.com:/repo/" ]; then exit 1; fi
if [ `gits resolve ^/path/to/test1 TEST1 scper` != "example.com:/path/to/test1" ]; then exit 1; fi
if [ `gits resolve ssh://example.org/test1 TEST1 scper` != "ssh://example.org/test1" ]; then exit 1; fi
if [ `gits resolve example.org:test1 TEST1 scper` != "example.org:test1" ]; then exit 1; fi

if [ `gits resolve test1 TEST1 fscper` != "example.com:/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve --fromcheckout test1 TEST1 fscper` != "example.com:/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve --no-fromcheckout test1 TEST1 fscper` != "example.com:/repo/dir/test1" ]; then exit 1; fi
if [ `gits resolve ../test1 TEST1 fscper` != "example.com:/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve .././//test1 TEST1 fscper` != "example.com:/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve /path/to/test1 TEST1 fscper` != "example.com:/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve .. TEST1 fscper` != "example.com:/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve ^/path/to/test1 TEST1 fscper` != "example.com:/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve ssh://example.org/test1 TEST1 fscper` != "example.com:/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve example.org:test1 TEST1 fscper` != "example.com:/repo/dir/TEST1" ]; then exit 1; fi

if [ `gits resolve test1 TEST1 scperu` != "user@example.com:/repo/dir/test1" ]; then exit 1; fi
if [ `gits resolve --fromcheckout test1 TEST1 scperu` != "user@example.com:/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve --no-fromcheckout test1 TEST1 scperu` != "user@example.com:/repo/dir/test1" ]; then exit 1; fi
if [ `gits resolve ../test1 TEST1 scperu` != "user@example.com:/repo/test1" ]; then exit 1; fi
if [ `gits resolve .././//test1 TEST1 scperu` != "user@example.com:/repo/test1" ]; then exit 1; fi
if [ `gits resolve /path/to/test1 TEST1 scperu` != "/path/to/test1" ]; then exit 1; fi
if [ `gits resolve .. TEST1 scperu` != "user@example.com:/repo/" ]; then exit 1; fi
if [ `gits resolve ^/path/to/test1 TEST1 scperu` != "user@example.com:/path/to/test1" ]; then exit 1; fi
if [ `gits resolve ssh://example.org/test1 TEST1 scperu` != "ssh://example.org/test1" ]; then exit 1; fi
if [ `gits resolve example.org:test1 TEST1 scperu` != "example.org:test1" ]; then exit 1; fi

if [ `gits resolve test1 TEST1 fscperu` != "user@example.com:/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve --fromcheckout test1 TEST1 fscperu` != "user@example.com:/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve --no-fromcheckout test1 TEST1 fscperu` != "user@example.com:/repo/dir/test1" ]; then exit 1; fi
if [ `gits resolve ../test1 TEST1 fscperu` != "user@example.com:/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve .././//test1 TEST1 fscperu` != "user@example.com:/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve /path/to/test1 TEST1 fscperu` != "user@example.com:/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve .. TEST1 fscperu` != "user@example.com:/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve ^/path/to/test1 TEST1 fscperu` != "user@example.com:/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve ssh://example.org/test1 TEST1 fscperu` != "user@example.com:/repo/dir/TEST1" ]; then exit 1; fi
if [ `gits resolve example.org:test1 TEST1 fscperu` != "user@example.com:/repo/dir/TEST1" ]; then exit 1; fi

if [ `gits resolve test1 TEST1 scperd` != "example.com:repo/test1" ]; then exit 1; fi
if [ `gits resolve --fromcheckout test1 TEST1 scperd` != "example.com:repo/TEST1" ]; then exit 1; fi
if [ `gits resolve --no-fromcheckout test1 TEST1 scperd` != "example.com:repo/test1" ]; then exit 1; fi
if [ `gits resolve ../test1 TEST1 scperd` != "example.com:test1" ]; then exit 1; fi
if [ `gits resolve .././//test1 TEST1 scperd` != "example.com:test1" ]; then exit 1; fi
if [ `gits resolve /path/to/test1 TEST1 scperd` != "/path/to/test1" ]; then exit 1; fi
if [ `gits resolve .. TEST1 scperd` != "example.com:" ]; then exit 1; fi
if [ `gits resolve ^/path/to/test1 TEST1 scperd` != "example.com:/path/to/test1" ]; then exit 1; fi
if [ `gits resolve ssh://example.org/test1 TEST1 scperd` != "ssh://example.org/test1" ]; then exit 1; fi
if [ `gits resolve example.org:test1 TEST1 scperd` != "example.org:test1" ]; then exit 1; fi

if [ `gits resolve test1 TEST1 fscperd` != "example.com:repo/TEST1" ]; then exit 1; fi
if [ `gits resolve --fromcheckout test1 TEST1 fscperd` != "example.com:repo/TEST1" ]; then exit 1; fi
if [ `gits resolve --no-fromcheckout test1 TEST1 fscperd` != "example.com:repo/test1" ]; then exit 1; fi
if [ `gits resolve ../test1 TEST1 fscperd` != "example.com:repo/TEST1" ]; then exit 1; fi
if [ `gits resolve .././//test1 TEST1 fscperd` != "example.com:repo/TEST1" ]; then exit 1; fi
if [ `gits resolve /path/to/test1 TEST1 fscperd` != "example.com:repo/TEST1" ]; then exit 1; fi
if [ `gits resolve .. TEST1 fscperd` != "example.com:repo/TEST1" ]; then exit 1; fi
if [ `gits resolve ^/path/to/test1 TEST1 fscperd` != "example.com:repo/TEST1" ]; then exit 1; fi
if [ `gits resolve ssh://example.org/test1 TEST1 fscperd` != "example.com:repo/TEST1" ]; then exit 1; fi
if [ `gits resolve example.org:test1 TEST1 fscperd` != "example.com:repo/TEST1" ]; then exit 1; fi



######################################################################
: "Prepare SuperDuper project of which the old thing is just a component"
git clone $BASE/checkdir/master2/top2 $BASE/checkdir/superduper
cd ../superduper
GITS_DIR=`pwd` gits prepare
gits attach ../sub21 sub21
gits attach --recursive=.gitslave ../../master/top submastertop
gits populate
for f in . ./sub21 ./submastertop ./submastertop/sub1 ./submastertop/sub2 ./submastertop/sub3
 do
  date >> $f/datelist
 done
gits commit -a -m "Combined superduper project"
gits push
: "Person 2 clones the new superproject"
gits clone $BASE/checkdir/master2/top2 $BASE/checkdir/superduper2
cd ../superduper2
for f in . ./sub21 ./submastertop ./submastertop/sub1 ./submastertop/sub2 ./submastertop/sub3
 do
  date >> $f/datelist
 done
gits commit -a -m "Fixes super-bug"
gits push
: "Person 2 makes (but does not push) a change"
for f in . ./sub21 ./submastertop ./submastertop/sub1 ./submastertop/sub2 ./submastertop/sub3
 do
  date >> $f/datelist
 done
gits commit -a -m "Fixes super-bug 2"
: "Person 1 gets the latest changes"
cd ../superduper
gits pull --rebase
: "Person 1 makes a shadow clone for special circumstances"
gits clone --fromcheckout ../superduper ../superduper1
: "Person 1 adds person 2 as a remote"
cd ../superduper1
gits remote add --fromcheckout othercheckout $BASE/checkdir/superduper2
gits fetch othercheckout
gits merge othercheckout/master
: "Person 1 adjusts newly obtained patch"
for f in . ./sub21 ./submastertop ./submastertop/sub1 ./submastertop/sub2 ./submastertop/sub3
 do
  date >> $f/datelist
 done
gits commit -a -m "Adjustment to super-bug 2"
: "Person 1 repoints origin to real upstream as a remote and pushes"
gits update-remote-url --no-fromcheckout origin $BASE/checkdir/master2/top2
gits push
: "Person 1 updates normal repo and then adjusts fix again"
cd ../superduper
gits pull
for f in . ./sub21 ./submastertop ./submastertop/sub1 ./submastertop/sub2 ./submastertop/sub3
 do
  date >> $f/datelist
 done
gits commit -a -m "Adjustment2 to super-bug 2"
: "Person 1 updates shadow checkout"
cd ../superduper1
gits update-remote-url --fromcheckout othercheckout $BASE/checkdir/superduper
gits fetch othercheckout
gits merge othercheckout/master
: "Person 1 adjusts final patch"
for f in . ./sub21 ./submastertop ./submastertop/sub1 ./submastertop/sub2 ./submastertop/sub3
 do
  date >> $f/datelist
 done
gits commit -a -m "Final adjustment to super-bug 2"
gits push
export GITSLAVE=.optslave
: "Prepare another SuperDuper project of which the old thing is just an optional component"
git clone $BASE/checkdir/master2/top2 $BASE/checkdir/superopt
cd ../superopt
GITS_DIR=`pwd` gits prepare
gits attach ../sub21 sub21
gits attach --recursive=.gitslave ../../master/top submastertop ifpresent
gits populate
gits push
: Try out attach reference
gits attach --reference=$BASE/checkdir/slave3 --recursive=.gitslave ../../master/top submastertop2
: "Now done with optional component"
gits release --just-ifpresent
: "Person 2 takes a look"
cd ..
gits clone --referencecheckout=$BASE/checkdir/superopt $BASE/checkdir/master2/top2 superopt2
cd superopt2
# Clean up after the reference
gits repack -a
find . -name datelist | while read f; do echo $f; date >> $f; done
gits commit -a -m "superopt update"
gits push
: "Person 2 takes a full look"
gits populate
gits --with-ifpresent populate
find . -name datelist | while read f; do echo $f; date >> $f; done
gits commit -a -m "superopt full update"
gits push
: "Person 2 is done"
gits release --all
